home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / utility / cica2db2.zip / CICA2DB.C next >
Text File  |  1992-05-19  |  4KB  |  198 lines

  1. /*
  2.    CICA2DB - Create a database importable file from cica's win3 index
  3.  
  4.     Author:         Hans van Oostrom
  5.                     hans@pine.circa.ufl.edu  INTERNET
  6.                     hans@ufpine              BITNET
  7.  
  8.     Date:           May 19, 1992
  9.  
  10.     Version:        1.2
  11.  
  12.     Modifications:  Updated the program because of a change of format of the
  13.                     index file.
  14.                     Once again fix changes to th index file.
  15.  
  16.     Status:         Public Domain
  17.                     You need not to send any money to use this, it's
  18.                     absolutely free.  Also the source code is provided, so
  19.                     make all the modifications you want. If you like it you
  20.                     can let me know if you want to.
  21.  
  22.  
  23.     Compiled with Borland C++ 3.00, also compatible with MSC 5.1
  24.  
  25. */
  26.  
  27. #include <stdio.h>
  28. #include <string.h>
  29.  
  30. #define TRUE    1
  31. #define FALSE    0
  32.  
  33. /*** parse the filename and description ************************************/
  34. int ParseFile(char *line)
  35. {
  36.     char temp[80];
  37.     int i=1;
  38.     char *tp=temp;
  39.     
  40.     if (strlen(line)<5) 
  41.     {
  42.         line[0]='\0';
  43.         return 0;
  44.     }
  45.     
  46.     strcpy(temp,line);
  47.     line[0] = '\"';
  48.     while (!isspace(*tp))
  49.     {
  50.         line[i++]=*tp;
  51.         ++tp;
  52.     }
  53.     line[i++] = '\"';
  54.     line[i++] = ',';
  55.     line[i++] = '\"';
  56.     
  57.     while (isspace(*tp)) ++tp;
  58.  
  59.     while (!isspace(*tp))
  60.     {
  61.         line[i++]=*tp;
  62.         ++tp;
  63.     }
  64.     line[i++] = '\"';
  65.     line[i++] = ',';
  66.     line[i++] = '\"';
  67.     
  68.     while (isspace(*tp)) ++tp;
  69.     
  70.     while (*tp!='\n')
  71.     {
  72.         line[i++]=*tp;
  73.         ++tp;
  74.     }
  75.     line[i++] = '\"';
  76.     line[i++] = '\0';
  77.     
  78.     return 0;
  79. }
  80.     
  81.  
  82. /*** parse the directory name.  Starts with win3\ **************************/
  83. int ParseDir(char *line)
  84. {
  85.     char temp[80];
  86.     int i=1;
  87.     char *tp=temp;
  88.     
  89.     if (strlen(line)<5) 
  90.     {
  91.         line[0]='\0';
  92.         return 0;
  93.     }
  94.     
  95.     strcpy(temp,line);
  96.     tp = strstr(tp, "win3" );
  97.     if (tp==NULL)
  98.     {
  99.         line[0]='\0';
  100.         return 0;
  101.     }
  102.     line[0] = '\"';
  103.  
  104.  
  105.     while ((*tp!='\n') && (*tp!=' '))    /* check for space and CR */
  106.     {
  107.         line[i++]=*tp;
  108.         ++tp;
  109.     }
  110.     line[i++] = '\"';
  111.     line[i++] = '\0';
  112.     
  113.     return 0;
  114. }
  115.  
  116.  
  117. /*** main program entry point *********************************************/
  118. void main(int argc, char *argv[])
  119. {
  120.     char line[80];
  121.     char dir[80];
  122.     FILE *in;
  123.     FILE *out;
  124.     char inname[80];
  125.     char outname[80];
  126.     int i;  
  127.     char star;    
  128.  
  129.     printf( "CICA2DB - Index to database converter\n");
  130.     printf( "      Version 1.2,  May 19, 1992\n" );
  131.     printf( "        by Hans van Oostrom\n" );
  132.     printf( "      hans@pine.circa.ufl.edu\n\n");
  133.  
  134.     switch(argc)                        /* handle command line parameters */
  135.     {
  136.         case 1:
  137.             printf( "Input name:  " );
  138.             gets( inname );
  139.             printf( "Output name: ");
  140.             gets( outname );
  141.             break;
  142.         case 2:
  143.             strcpy(inname, argv[1]);
  144.             printf( "Output name: ");
  145.             gets( outname );
  146.             break;
  147.         case 3:
  148.             strcpy(inname, argv[1]);
  149.             strcpy(outname, argv[2]);
  150.             break;
  151.         default:
  152.             printf( "Usage: %s <inputfile> <outputfile>\n", argv[0] );
  153.             exit(1);
  154.     }
  155.  
  156.     if ((in=fopen(inname, "r"))==NULL)
  157.     {
  158.         printf( "Error opening file: %s\n", inname );
  159.         exit(2);
  160.     }
  161.     if ((out=fopen(outname, "w"))==NULL)
  162.     {
  163.         printf( "Error opening file: %s\n", outname );
  164.         exit(2);
  165.     }
  166.     
  167.     fgets(line, 80, in);
  168.     while (!feof(in))
  169.     {
  170.         if (fgets( line, 80, in )==NULL) break;
  171.  
  172.         switch(line[0])
  173.         {
  174.             case '\n':
  175.             case ' ':
  176.                 break;
  177.             case '*':
  178.                 if (star) break;
  179.                 ParseDir(line);
  180.                 if (line[0]!='\0') 
  181.                 {
  182.                     star=TRUE;
  183.                     strcpy(dir, line);
  184.                 }
  185.                 break;
  186.             default:
  187.                 star = FALSE;
  188.                 ParseFile(line);
  189.                 if (line[0] != 0)
  190.                     fprintf( out, "%s,%s\n", dir, line );
  191.                 break;
  192.         }
  193.     }   
  194.     fclose(in);
  195.     fclose(out);
  196.     printf( "Conversion complete.\n" );
  197. }
  198.